package com.mdd.admin.controller;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IUserCommemorateService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.UserCommemorateCreateValidate;
import com.mdd.admin.validate.UserCommemorateUpdateValidate;
import com.mdd.admin.validate.UserCommemorateSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.UserCommemorateListedVo;
import com.mdd.admin.vo.UserCommemorateDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/commemorate")
@Api(tags = "纪念日提醒管理")
public class UserCommemorateController {

    @Resource
    IUserCommemorateService iUserCommemorateService;

    @GetMapping("/list")
    @ApiOperation(value="纪念日提醒列表")
    public AjaxResult<PageResult<UserCommemorateListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated UserCommemorateSearchValidate searchValidate) {
        PageResult<UserCommemorateListedVo> list = iUserCommemorateService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="纪念日提醒详情")
    public AjaxResult<UserCommemorateDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        UserCommemorateDetailVo detail = iUserCommemorateService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "纪念日提醒新增")
    @PostMapping("/add")
    @ApiOperation(value="纪念日提醒新增")
    public AjaxResult<Object> add(@Validated @RequestBody UserCommemorateCreateValidate createValidate) {
        iUserCommemorateService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "纪念日提醒编辑")
    @PostMapping("/edit")
    @ApiOperation(value="纪念日提醒编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody UserCommemorateUpdateValidate updateValidate) {
        iUserCommemorateService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "纪念日提醒删除")
    @PostMapping("/del")
    @ApiOperation(value="纪念日提醒删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iUserCommemorateService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
